package cn.qxq1.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhangying
 * @date 2020-04-26
 * @description
 */
@Controller
public class TestController {

    @RequestMapping("test")
    @ResponseBody
    public String test() {
        return "test ok";
    }

    @RequestMapping("404.html")
    public String page404(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("request:" + request);
        System.out.println("response = " + response);
//        response.setStatus(200);
//        if (request.getMethod().equalsIgnoreCase("get")) {
//            response.sendRedirect("/404-post");
//        }
        return "404";
    }
    @RequestMapping("404-post")
    @ResponseBody
    public String page404Post(HttpServletRequest request, HttpServletResponse response) {
        Map map = new HashMap();
        map.put("message", "post 404");
        return JSON.toJSONString(map);
    }

}
